package lhc.alg.top100;

/**
 * description: https://leetcode.cn/problems/number-of-1-bits/
 *  位1的个数
 * author: hongchen.liao
 * date:  2022/9/10
 */
public class _191_ {
    public class Solution {
        // you need to treat n as an unsigned value
        public int hammingWeight(int n) {
            int ret = 0;
            for (int i = 0; i < 32; i++) {
                if ((n & (1 << i)) != 0) {
                    ret++;
                }
            }
            return ret;
        }
    }

}
